package com.cyanz.test;

import com.cyanz.dao.StudentMapper;
import com.cyanz.dao.StudentMapperInterface;
import com.cyanz.entity.Student;
import com.cyanz.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

/**
 * @author Scyanz
 * @description 测试
 * @date 2020/10/10 10:34
 */
public class Demo2 {

    @Test
    public void addMethod(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        StudentMapperInterface studentMapper = sqlSession.getMapper(StudentMapperInterface.class);

        List<Student> studentList = Arrays.asList(
                new Student(null, "普京", 12, "1234"),
                new Student(null, "梅德韦杰夫", 12, "1234"),
                new Student(null, "普希金", 12, "1234")
        );

        studentMapper.addBatchStudent(studentList);
        sqlSession.commit();
        sqlSession.close();
    }

    @Test
    public void Delete(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        mapper.deleteBatchById(new Integer[]{25,26});
        sqlSession.commit();
        sqlSession.close();
    }

    @Test
    public void update(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
        Student student = new Student();
        student.setStuId(30);
        student.setStuName("斯大林");
        studentMapper.update(student);
        sqlSession.commit();
        sqlSession.close();
    }
//
    @Test
    public void list(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
        studentMapper.list("普京",null,"").stream().forEach(n->{
            System.out.println(n.getStuId()+","+n.getStuName());
        });
    }

    @Test
    public void listAge(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
        studentMapper.listAge("",null,5,"").stream().forEach(n->{
            System.out.println(n.getStuId()+","+n.getStuName());
        });
    }

}
